package com.egg.mall.controller.api;

import com.egg.common.core.model.controller.ApiController;
import com.egg.common.core.model.response.ResponseData;
import com.egg.common.util.OptionalUtil;
import com.egg.mall.model.response.web.CategoryTree;
import com.egg.mall.service.category.ICategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author east
 * @since 2023-05-09
 */
@Slf4j
@Api(tags = ApiController.API_PREFIX + "品类")
@RestController
@RequestMapping("/category")
public class ApiCategoryController extends ApiController {


    @Autowired
    private ICategoryService categoryService;


    @ApiOperation(value = "品类树查询")
    @GetMapping("/tree")
    public ResponseData<List<CategoryTree>> categoryListGet(
            @ApiParam(value = "上级品类ID") @RequestParam(value = "pid", required = false) String pid
    ) {
        List<CategoryTree> tree = categoryService.tree(OptionalUtil.build(pid));
        return ResponseData.success(tree);
    }


}

